package com.nuanshui.heatedloan.task.facade.vo;

import java.io.IOException;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

import com.nuanshui.framework.lang.DateUtil;
import com.nuanshui.framework.utils.serializer.JavaSerializer;
import com.nuanshui.heatedloan.task.facade.bean.JobParams;
import com.nuanshui.heatedloan.task.facade.model.QrtzTriggers;

public class QrtzTriggersVO extends QrtzTriggers {
	
	private JobParams jobParams = null;
	public String getShowNextFireTime() {
		if(this.getNextFireTime() == null || this.getNextFireTime().longValue()<=0) return "无";
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(this.getNextFireTime());
		return DateUtil.format(calendar.getTime(), "yyyy-MM-dd HH:mm:ss");
	}
	
	public String getShowPrevFireTime() {
		if(this.getPrevFireTime() == null || this.getPrevFireTime().longValue()<=0) return "无";

		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(this.getPrevFireTime());
		return DateUtil.format(calendar.getTime(), "yyyy-MM-dd HH:mm:ss");
	}
	
	
	public String getShowStartTime() {
		if(this.getStartTime() == null || this.getStartTime().longValue() <=0) return "无";
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(this.getStartTime());
		return DateUtil.format(calendar.getTime(), "yyyy-MM-dd HH:mm:ss");
		
	}
	public String getShowEndTime() {
		if(this.getEndTime() == null || this.getEndTime().longValue() <=0) return "无";
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(this.getEndTime());
		return DateUtil.format(calendar.getTime(), "yyyyMMdd HH:mm:ss");
		
	}
	
	public Map getDataMap() {
		if(this.getJobData() == null) return null;
		if(this.getJobData().length == 0) return new HashMap();
		try {
			
			Map map =  (Map) new JavaSerializer().deserialize(this.getJobData());
			return map;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	  
	public JobParams getJobParams() {
		if(jobParams!=null) return jobParams;
		Map map = getDataMap();
		if(map!=null)  {
			 jobParams =  (JobParams) map.get("job_params");
		}
		return jobParams;
	}
	
	public String getJobCode() {
		JobParams jobParams =  getJobParams();
		if(jobParams!=null) return jobParams.getJobCode();
		return "";
	}

}
